/****** Object: View [dbo].[vw_DeductibleAR]   Script Date: 2014-01-19 21:49:13 ******/
USE [SHMIS];
GO
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_DeductibleAR]'))
BEGIN
DROP VIEW [dbo].[vw_DeductibleAR];
END
GO

SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE VIEW [dbo].[vw_DeductibleAR]
AS
   SELECT ar.Customer_Code,
          ar.Contract_Num,
          ar.Serial_Num,
          ar.Customer_Simple_Code,
          ar.Customer_Simple_Name,
          ar.[Date],
          ar.Amount,
          ar.Amount_Type,
          ar.Duration_Begin,
          ar.Duration_End,
          ar.Adjust_Serial_Num,
          ar.Verify_Serial_Num,
          ar.Depart_Id,
          ar.cre_user,
          ar.cre_date,
          ar.chg_user,
          ar.chg_date,
          ar.verified,
          ar.verify_user,
          ar.audited,
          ar.audit_user,
          ar.deleted,
          Record_Check,
          CASE isnull (ar.Adjust_Serial_Num, '')
             WHEN '' THEN ar.Serial_Num
             ELSE ar.Adjust_Serial_Num
          END
             AS Order_Serial_Num
     FROM HD_AccountReceivable ar
          LEFT JOIN
          HD_DeductibleARManage dar
             ON     ar.Customer_Code = dar.Customer_Code
                AND ar.Contract_Num = dar.Contract_Num
                AND ar.Serial_Num = dar.Serial_Num
                AND ar.deleted = '0'
                AND ar.verified = '1'
                AND dar.Deleted = '0'
                AND dar.Verified = '1'
GO

